package com.zhuiYun.project.api.slideshow.service.serviceImpl;

import com.zhuiYun.project.api.handworkDiy.model.HandworkDiyModel;
import com.zhuiYun.project.api.order.model.orderModel;
import com.zhuiYun.project.api.slideshow.entity.Slidsshow;
import com.zhuiYun.project.api.slideshow.mapper.slidesShowmapper;
import com.zhuiYun.project.api.slideshow.model.slidesShowModel;
import com.zhuiYun.project.api.slideshow.service.slidesShowService;
import com.zhuiYun.project.util.BeanUtils;
import com.zhuiYun.project.util.PrimaryKeyUtil;
import com.zhuiYun.project.util.UploadFileUtils;
import com.zhuiYun.project.util.pageUtil.MybatisPageHelper;
import com.zhuiYun.project.util.pageUtil.PageRequest;
import com.zhuiYun.project.util.pageUtil.PageResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;

/**
 * @Author 小江
 * @Description //TODO 轮播图、
 * @Date 9:32 2023/4/5
 **/
@Service
public class slidesShowServiceImpl  implements slidesShowService {
    @Autowired
    slidesShowmapper  slidesshowmapper;

    @Autowired
    PrimaryKeyUtil primaryKeyUtil;

    /**
     * @Author 小江
     * @Description //TODO 轮播图全查
     * @Date 9:03 2023/4/5
     **/
    @Override
    public PageResult slidsShowList(PageRequest pageResult) {
        int pageNum = pageResult.getPageNum();
        List<Slidsshow> slidsshows = slidesshowmapper.slidsShowList(pageResult);
        MybatisPageHelper.startPage(pageResult);
        return MybatisPageHelper.getPageResult(slidsshows);
    }

    /**
     * @Author 小江
     * @Description //TODO  删除轮播图
     * @Date 9:41 2023/4/5
     **/
    @Override
    public int slidshowDel(Integer id) {
        Slidsshow slidsshow = new Slidsshow();
        slidsshow.setId(id);
        slidsshow.setDeleteFlag(1);
        int i = slidesshowmapper.updateByPrimaryKeySelective(slidsshow);
        return i;
    }


    /**
     * @Author 小江
     * @Description //TODO 添加图片
     * @Date 13:41 2023/4/5
     **/

    @Override
    public int slideseAdd(MultipartFile imageFile, slidesShowModel slidesShowModel) {
        slidesShowModel.setCreateTime(new Date());
        slidesShowModel.setDeleteFlag(0);
        int i=0;
        if(imageFile!=null){
            String upl = UploadFileUtils.uploadFile(imageFile);
                String s = UploadFileUtils.uploadFile(imageFile);
                 if(!StringUtils.isEmpty(s)){
                    slidesShowModel.setImageId(upl);
                }
            }
        Slidsshow slidsshow = new Slidsshow();
        BeanUtils.copy(slidesShowModel, slidsshow);
        if (slidsshow.getId()> 0){
            i = slidesshowmapper.updateByPrimaryKeySelective(slidsshow);
        }else{
            i = slidesshowmapper.insertSelective(slidsshow);
        }
        return i;

    }


}
